<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCommodityInfosTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('commodity_infos', function (Blueprint $table) {
            $table->increments('commodity_info_id')->comment("商品规格信息ID,自增");
            $table->integer('commodity_id')->unsigned()->comment("所属商品ID");
            $table->string('commodity_classify_id')->nullable()->comment("所属分类ID,逗号隔开");
            $table->integer('commodity_size_id')->unsigned()->comment("商品尺码");
            $table->integer('commodity_color_id')->unsigned()->comment("商品颜色");
            $table->integer('commodity_info_number')->unsigned()->comment("商品库存");
            $table->string('commodity_info_price',50)->comment("商品价格");
            $table->string('info_img_url')->nullable()->comment("规格图");
            $table->engine = 'InnoDB';
            $table->index(['commodity_info_id','commodity_id','commodity_size_id','commodity_color_id'],"commodity_info_id");
            $table->foreign('commodity_id')->references('commodity_id')->on('commoditys');
            $table->foreign('commodity_size_id')->references('commodity_size_id')->on('commodity_sizes');
            $table->foreign('commodity_color_id')->references('commodity_color_id')->on('commodity_colors');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('commodity_infos');
    }
}
